// run: $exec < input
// opt: 0
// flag: -g
#include <iostream>

int const inf  = 1 << 30;
int const maxn = 2000;
char a[maxn][maxn];
int n, m;
int tot;
int left = 1 << 30, up = 1 << 30;

int con_to_right(int x, int y)
{
	for (; y <= m; y++)
		if (a[x][y] != 'X') break;
	return y - 1;
}

int con_to_left(int x, int y)
{
	for (; y > 0; y--)
		if (a[x][y] != 'X') break;
	return y + 1;
}

int down(int x, int y, int r)
{
	int t = x + 1;
	for (; t <= n; t++)
		if (a[t][y] != 'X' || con_to_right(t, y) != r) break;
	return t - 1;
}

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			std::cin >> a[i][j];
			if (a[i][j] == 'X') {
				tot++;
				if (i < left) {
					left = i; up = j;
				}
			}
		}
	}

	int ansx = inf, ansy = inf;
	int j = up, sum = 0, h;
	bool ok = true;
	for (int i = left; i <= n; i = h + 1) {
		int r = con_to_right(i, j);
		h = down(i, j, r);
		sum += (r - j + 1) * (h - i + 1);
		if ((h - i + 1) > ansx) break;
		ansx = h - i + 1;
		if (h == n) continue;
		if (a[h + 1][r] != 'X') break;
		int tl = con_to_left(h + 1, r);
		if (tl < j) break;
		if (r - j + 1 > ansy) break;
		ok = false;
		ansy = r - tl + 1;
		j = tl;
	}
	if (ok) ansy = 1;
	if (sum != tot) {
		std::cout << "-1";
	} else
		std::cout << ansy * ansx << "\n";
}

